<?php
require("../../class2.php");
require("library/api.php");
require(HEADERF);

// Make connection and send the query
$gateways = new db;
$gateways->db_Select("e107shop_gateways", "*", "identifier='payson'");

// Read out the Payson Values from the Gateway table
while ($gatewayRow=$gateways->db_Fetch()) {
    $PS_AgentId     = $gatewayRow['account'];
    $PS_Url         = $gatewayRow['field1'];
    $PS_Key         = $gatewayRow['field2'];
    $PS_Email       = $gatewayRow['field5'];
    $PS_Guarantee   = $gatewayRow['field6'];
}

$strOkURL = $_REQUEST["OkURL"];
$strRefNr = $_REQUEST["RefNr"];
$strPaysonRef = $_REQUEST["Paysonref"];

$strTestMD5String = $strOkURL . $strPaysonRef . $PS_Key;

$strMD5Hash = md5($strTestMD5String);

if($strMD5Hash == $_REQUEST["MD5"]){
    //Korrekt anrop från Payson
    $display = "
    Rätt!<br>
    OkUrl: " . $strOkURL . "<br>
    RefNr: " . $strRefNr . "<br>
    PaysonRef: " . $strPaysonRef . "<br>";
} else {
    //Felaktigt anrop från någon annan.
    $display = "Felaktig MD5-summa!";
}

$ns->tablerender(lan_pp_accepted, $display);

require(FOOTERF);
